﻿using System;
using System.Collections.Generic;

namespace CID.Execution.Controller
{
    sealed class DeploymentStateRepository
    {
        public static readonly DeploymentStateRepository Instance = new DeploymentStateRepository();

        private IDictionary<Guid, IDeploymentState> deploymentStateMap;

        private DeploymentStateRepository()
        {
            deploymentStateMap = new Dictionary<Guid, IDeploymentState>();
        }

        public void Add(IDeploymentState deploymentState)
        {
            if (!deploymentStateMap.ContainsKey(deploymentState.DeploymentUniqueIdentifier))
                deploymentStateMap.Add(deploymentState.DeploymentUniqueIdentifier, deploymentState);
        }

        public void Remove(IDeploymentState deploymentState)
        {
            if (deploymentStateMap.ContainsKey(deploymentState.DeploymentUniqueIdentifier))
                deploymentStateMap.Remove(deploymentState.DeploymentUniqueIdentifier);
        }

        public IDeploymentState Get(Guid deploymentUniqueIdentifier)
        {
            IDeploymentState result = null;
            if (deploymentStateMap.ContainsKey(deploymentUniqueIdentifier))
                result = deploymentStateMap[deploymentUniqueIdentifier];
            return result;
        }

        public int Count
        {
            get { return deploymentStateMap.Count; }
        }
    }
}
